#include <stdio.h>

int num[29];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&num[i]);
    int max = -10000;
    int min = 10000;
    int wheremax = 0;
    int wheremin = 0;
    for(int i=0;i<n;i++) 
    {
        scanf("%d",&num[i]);
        if(num[i] < min)
        {
            min = num[i];
            wheremin = i;
        }
    }
    int t = num[0];
    num[0] = min;
    num[wheremin] = t;
    for(int i=0;i<n;i++)
    {
        if(num[i] > max)
        {
            max = num[i];
            wheremax = i;
        }
    }
    t = num[n-1];
    num[n-1] = max;
    num[wheremax] = t;
    
    for(int i=0;i<n;i++) printf("%d ",num[i]);
    return 0;
}